package com.killLog.api;

import com.killLog.common.CurrentUser;
import com.killLog.common.Result;
import com.killLog.common.TokenUtils;
import com.killLog.dto.LoginDto;
import com.killLog.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
登录功能
*/
@RestController
@RequestMapping("/login")
public class LoginApi {
    @Autowired
    private LoginService loginService;
    
    /**
    登录功能
    */
    @PostMapping
    public Result userLogin(@RequestBody LoginDto loginDto){
        //调用登录业务 返回CurrentUser相关信息
        CurrentUser currentUser = loginService.findUser(loginDto);
        //登录逻辑
        String token = TokenUtils.loginSign(currentUser, loginDto.getU_pwd());
        //向客户端发送token
        return Result.OK(token);
    }
}
